<%--
  Created by IntelliJ IDEA.
  User: W
  Date: 2025/10/21
  Time: 18:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<div>
    <input type="text" id="username">
</div>
<div>
    <input type="text" id="password">

</div>
<input type="button" value="登录" id="loginBtn">

</body>
</html>

<script type="text/javascript" src="js/jquery-3.6.0.js"></script>
<script type="text/javascript">
    $(function () {
        $("#loginBtn").click(function () {
            $.ajax({
                url: 'login',
                type: 'post',
                contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
                data: {
                    username: $("#username").val(),
                    password: $("#password").val()
                },
                success: function (resp) {
                    if (resp === "1") {
                        window.location.href = "main.jsp";
                    } else if (resp === "-1") {
                        alert("账号不存在");
                    } else {
                        alert("账号或密码错误");
                    }
                }
            })
        });
    })
</script>
